import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
import { fileURLToPath, URL } from 'url'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// https://vite.dev/config/
export default defineConfig({
    base: '/admin/',
    plugins: [
        vue(),
        AutoImport({
            imports: [
                // 自动导入 Vue 相关函数
                'vue',
                'vue-router',
                'pinia'
            ],
            dts: 'src/auto-imports.d.ts',
            dirs: [
                './src/composables/**',
                './src/stores/**',
                './src/utils/**'
            ],
            eslintrc: {
                enabled: true,
                filepath: './.eslintrc-auto-import.json',
                globalsPropValue: true,
            },
            vueTemplate: true,
        }),
        Components({
            directoryAsNamespace: true,
            resolvers: [
                AntDesignVueResolver({
                    importStyle: 'less',
                    resolveIcons: true,
                })
            ],
            dts: true,
        }),
        createSvgIconsPlugin({
            iconDirs: [fileURLToPath(new URL('./src/assets/icons', import.meta.url))],
            symbolId: 'local-icon-[dir]-[name]'
        }),
        vueSetupExtend()
    ],
    css: {
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
                modifyVars: {
                    'root-entry-name': 'default'
                }
            },
        },
    },
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src')
        }
    }
})
